package org.hyl.javabase.多线程;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

import org.hyl.javabase.多线程.service.CallableThread;

public class model {
	public static void main(String[] arg) {
		// process p = new process();
		// p.execbat0();
		 //p.execjava0();
		 //fun0_1() ;
		// fun1_1();
		// fun1_2();
		// fun2();
		// fun3();
		// fun3_1();
		// fun4();
		 fun4_1();
	}

	public static void fun0_1() {
		System.out.println("fun0_1----");
		thread1 mt1 = new thread1("t1");// 实例化对象
		thread1 mt2 = new thread1("t2");// 实例化对象
		//mt1.run();// 调用线程主体
		//mt2.run();// 调用线程主体
		mt1.start();// 调用线程主体
		mt2.start();// 调用线程主体

	}

	public static void fun0_2() {

		thread2 mt1 = new thread2("线程A");// 实例化对象
		thread2 mt2 = new thread2("线程B");
		Thread t1 = new Thread(mt1);// 实例化Thread类对象
		Thread t2 = new Thread(mt2);
		t1.start();// 启动多线程
		t2.start();
	}

	public static void fun1_1() {

		thread1 mt1 = new thread1("线程A");// 实例化对象
		Thread t1 = new Thread(mt1, "t1");// 实例化Thread类对象
		Thread t2 = new Thread(mt1, "t2");
		t1.start();// 启动多线程和
		t2.start();
	}

	public static void fun1_2() {

		thread2 mt1 = new thread2("线程A");
		Thread t1 = new Thread(mt1, "t1");// 实例化Thread类对象
		Thread t2 = new Thread(mt1, "t2");
		t1.start();// 启动多线程和
		t2.start();
	}

	public static void fun2() {
		new Thread(new Runnable() {
			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(10);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("bbbbbbbbbbb");
				}
			}
		}).start();

	}
	 public static void fun2_1() {
		new Thread(new Runnable() {
			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(10);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("bbbbbbbbbbb");
				}
			}
		}).start();

	}
	public static void fun6_1() {
		CallableThread ctt = new CallableThread();
		FutureTask<Integer> ft = new FutureTask<>(ctt);
		for (int i = 0; i < 100; i++) {
			System.out.println(Thread.currentThread().getName() + " 的循环变量i的值" + i);
			if (i == 20) {
				new Thread(ft, "有返回值的线程").start();
			}
		}
		try {
			System.out.println("子线程的返回值：" + ft.get());
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}

	}

	public static void fun3() {
		System.out.println(Thread.currentThread().getName() + "主线程运行开始!");
		thread3 mTh1 = new thread3("A");
		thread3 mTh2 = new thread3("B");
		mTh1.start();
		mTh2.start();
		System.out.println(Thread.currentThread().getName() + "主线程运行结束!");
		System.out.println(Thread.currentThread().getName() + "主bbb程运行结束!");

	}

	public static void fun3_1() {
		System.out.println(Thread.currentThread().getName() + "主线程运行开始!");
		thread3 mTh1 = new thread3("A");
		thread3 mTh2 = new thread3("B");
		mTh1.start();
		mTh2.start();
//		try {
//			mTh1.join();
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
//		try {
//			mTh2.join();
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
		System.out.println(Thread.currentThread().getName() + "主线程运行结束!");

	}

	public static void fun4() {

		thread4 yt1 = new thread4("张三");
		//thread4 yt2 = new thread4("李四");
		yt1.start();
	//	yt2.start();
	}

	public static void fun4_1() {
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(Thread.currentThread().getName() + "主线程运行结束!");
	}
	
	
}
